package com.hm.manage.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hm.common.annotation.Log;
import com.hm.common.core.controller.BaseController;
import com.hm.common.core.domain.AjaxResult;
import com.hm.common.enums.BusinessType;
import com.hm.manage.domain.Media;
import com.hm.manage.service.IMediaService;
import com.hm.common.utils.poi.ExcelUtil;
import com.hm.common.core.page.TableDataInfo;

/**
 * 媒体列Controller
 * 
 * @author hm
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/manage/media")
public class MediaController extends BaseController
{
    @Autowired
    private IMediaService mediaService;

    /**
     * 查询媒体列列表
     */
    @PreAuthorize("@ss.hasPermi('manage:media:list')")
    @GetMapping("/list")
    public TableDataInfo list(Media media)
    {
        startPage();
        List<Media> list = mediaService.selectMediaList(media);
        return getDataTable(list);
    }

    /**
     * 导出媒体列列表
     */
    @PreAuthorize("@ss.hasPermi('manage:media:export')")
    @Log(title = "媒体列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Media media)
    {
        List<Media> list = mediaService.selectMediaList(media);
        ExcelUtil<Media> util = new ExcelUtil<Media>(Media.class);
        util.exportExcel(response, list, "媒体列数据");
    }

    /**
     * 获取媒体列详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:media:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mediaService.selectMediaById(id));
    }

    /**
     * 新增媒体列
     */
    @PreAuthorize("@ss.hasPermi('manage:media:add')")
    @Log(title = "媒体列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Media media)
    {
        return toAjax(mediaService.insertMedia(media));
    }

    /**
     * 修改媒体列
     */
    @PreAuthorize("@ss.hasPermi('manage:media:edit')")
    @Log(title = "媒体列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Media media)
    {
        return toAjax(mediaService.updateMedia(media));
    }

    /**
     * 删除媒体列
     */
    @PreAuthorize("@ss.hasPermi('manage:media:remove')")
    @Log(title = "媒体列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mediaService.deleteMediaByIds(ids));
    }
}
